/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Facade;

import Entity.Utente;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Vito
 */
@Stateless
public class UtenteFacade extends AbstractFacade<Utente> implements UtenteFacadeLocal {
    @PersistenceContext(unitName = "EnterpriseApplication1-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UtenteFacade() {
        super(Utente.class);
    }

    @Override
    public Utente login(String username, String password){
        List<Utente> ut = null;
        Utente ret=null;
        try{
            ut = em.createNamedQuery("Utente.login").setParameter("username", username).setParameter("password", password).getResultList();
        }catch(Exception e){}
        if(ut!=null && ut.size()==1)
            ret=ut.get(0);
        return ret;
    }

    @Override
    public Utente findByUsername(String username){
        List<Utente> ut = null;
        Utente ret=null;
        try{
            ut = em.createNamedQuery("Utente.findByUsername").setParameter("username", username).getResultList();
        }catch(Exception e){}
        if(ut!=null && ut.size()==1)
            ret=ut.get(0);
        return ret;
    }

}
